home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / LList Mgr / LList Mgr For Think Pascal / LList.p < prev    next >
Encoding:
Text File  |  1994-05-22  |  17.3 KB  |  450 lines  |  [TEXT/PJMM]

  1. {************************************************************}
  2. {*                                                            *}
  3. {* LList.p                                                    *}
  4. {*                                                            *}
  5. {* Version 1.4, May 1994, added ignoreCase to LLSearch,        *}
  6. {*                          added drawNow to LLDoDraw,        *}
  7. {*                          added LLSort function                *}
  8. {* Version 1.3, April 1994, fixed bug w/no scroll bar,        *}
  9. {*                            LLDoDraw(theList, 1) no longer     *}
  10. {*                            auto-redraws the list so call     *}
  11. {*                            LLUpdate if necessary            *}
  12. {* Version 1.2, December 1993, added column frame option,    *}
  13. {*                               condenses type if needed,    *}
  14. {*                               added LLRect function,        *}
  15. {*                               fixed LLAddRow redraw bug    *}
  16. {* Version 1.1, November 1993, fixed thumb scrolling bug    *}
  17. {* Version 1.0, September 1993                                *}
  18. {* Tad Woods, T&T Software, 70312,3552 on CompuServe        *}
  19. {*                                                            *}
  20. {* LList is an alternative list manager to the standard        *}
  21. {* toolbox list manager. The advantages of LList are the    *}
  22. {* abilities to have variable width    columns, a different     *}
  23. {* text style for each column, and lists larger than 32K.    *}
  24. {* Unlike the standard list manager, LList only    scrolls        *}
  25. {* vertically, requires a fixed number of columns to        *}
  26. {* be set when the list is created via LLNew, and entire    *}
  27. {* rows, not individual cells, can be highlighted.            *}
  28. {* LList has about the same performance and the function    *}
  29. {* calls are similar to the toolbox list manager.            *}
  30. {* LLists may be unlimited total size, but individual        *}
  31. {* cells may not contain data bigger than 32K. Currently     *}
  32. {* LList is totally pointer based.                            *}
  33. {*                                                            *}
  34. {* LList has been tested and used but comes with no            *}
  35. {* guarantees. You may include LList with your own            *}
  36. {* compiled code. You may not sell or distribute LList        *}
  37. {* source code without permission of T&T Software.            *}
  38. {* Send comments or problem reports to the address above.    *}
  39. {*                                                            *}
  40. {************************************************************}
  41.  
  42. unit LList;
  43.  
  44. interface
  45.  
  46.     const
  47. {Values for selFlags}
  48.         LLOnlyOne = -128;        {only one cell can be selected at a time}
  49.         LLExtendDrag = 64;    {drag extends without shift key down}
  50.         LLNoDisjoint = 32;    {click deselects all previous selections}
  51.         LLNoExtend = 16;        {shift won't extend selection}
  52.         LLUseSense = 4;        {shift senses state of initial cell}
  53.         LLNoNilHilite = 2;    {don't highlight empty rows}
  54.  
  55.     type
  56.         LColDescPtr = ^LColDescRec;
  57.         LColDescRec = packed record    {Description of how to draw a column}
  58.                 width: integer;        {width in pixels, default is list width div by number of cols}
  59.                 style: integer;        {TextFace values, default is plain}
  60.                 justify: integer;    {0=left justify in cell (default), 1=center, -1=right}
  61.                 dodraw: integer;    {1=draw column (default), 0=don't draw column}
  62.                 highlight: integer;    {1=highlight column (default), 0=don't highlight column}
  63.                 frame: integer;
  64.         {$0008 frame left, $0004 right, $0002 top, $0001 bottom, $000F all}
  65.             end;
  66.  
  67.         LColPtr = ^LColRec;    {Column data}
  68.         LColRec = packed record
  69.                 data: Ptr;
  70.                 dataLen: integer;
  71.             end;
  72.  
  73.         LRowPtr = ^LRowRec;    {Row data}
  74.         LRowRec = packed record
  75.                 nextRow: LRowPtr;
  76.                 prevRow: LRowPtr;
  77.                 needDraw: integer;
  78.                 selected: integer;
  79.                 col: array[0..999] of LColRec;
  80.             end;
  81.  
  82.         LListPtr = ^LListRec;
  83.         LListRec = packed record
  84.                 view: Rect;                {display rectangle in local coords}
  85.                 window: WindowPtr;        {window where list resides}
  86.                 scroll: ControlHandle;    {ControlRecord for scroll bar}
  87.                 font: integer;            {list font}
  88.                 size: integer;            {list font size}
  89.                 height: integer;        {list line height in pixels}
  90.                 baseline: integer;        {pixels from bottom of text to bottom of row}
  91.                 indent: integer;        {pixels to indent from edge of column}
  92.                 dodraw: integer;
  93.                 selFlags: char;            {determines how selection is performed with mouse}
  94.                 activeFlag: char;
  95.                 row: LRowPtr;            {pointer to first LRow}
  96.                 lastClkRow: LRowPtr;    {pointer to last row clicked in}
  97.                 lastClkTime: longint;
  98.                 numOfRows: integer;            {number of rows in list}
  99.                 firstVisRowNum: integer;    {number of first visible row in list}
  100.                 numOfVisRows: integer;        {number of visible rows in view Rect}
  101.                 numOfColumns: integer;        {number of columns in list}
  102.                 refCon: longint;    {for your use}
  103.                 colDesc: array[0..999] of LColDescRec;
  104.             end;
  105.  
  106. {************************************************************}
  107. {*                                                            *}
  108. {* LLActivate                                                *}
  109. {*                                                            *}
  110. {*  -> theList        pointer to LList                        *}
  111. {*  -> activate        1=activate, 0=deactivate                *}
  112. {*                                                            *}
  113. {* Activates or deactivates a LList. Call after an            *}
  114. {* activate event.                                            *}
  115. {*                                                            *}
  116. {************************************************************}
  117.     procedure LLActivate (theList: LListPtr; activate: integer);
  118.  
  119.  
  120. {************************************************************}
  121. {*                                                            *}
  122. {* LLAddRow            returns pointer to new row or NULL        *}
  123. {*                    (returns NULL if there's not enough     *}
  124. {*                    memory)                                    *}
  125. {*                                                            *}
  126. {*  -> theList        pointer to LList                        *}
  127. {*  -> beforeRow    pointer to row that new row will come    *}
  128. {*                    before                                    *}
  129. {*                                                            *}
  130. {* Adds a new row to a LList. If beforeRow = NULL a row        *}
  131. {* will be added to the end of the list.                    *}
  132. {*                                                            *}
  133. {************************************************************}
  134.     function LLAddRow (theList: LListPtr; beforeRow: LRowPtr): LRowPtr;
  135.  
  136.  
  137. {************************************************************}
  138. {*                                                            *}
  139. {* LLClick            returns 1 if user double-clicks in         *}
  140. {*                    list otherwise returns 0                *}
  141. {*                                                            *}
  142. {*  -> theList        pointer to LList                        *}
  143. {*  -> localPoint    click location in local coordinates        *}
  144. {*  -> modifiers    shift, cmd, etc. from event record        *}
  145. {*                                                            *}
  146. {* Processes mouse-down for list dragging and selection.    *}
  147. {* Call LLClick when a mousedown event occurs inside the    *}
  148. {* list view area of a window. LLClick performs row         *}
  149. {* selection according to criteria established by the        *}
  150. {* bits of LList.selFlags.                                    *}
  151. {*                                                            *}
  152. {************************************************************}
  153.     function LLClick (theList: LListPtr; localPoint: Point; modifiers: integer): integer;
  154.  
  155.  
  156. {************************************************************}
  157. {*                                                            *}
  158. {* LLDelRow                                                    *}
  159. {*                                                            *}
  160. {*  -> theList        pointer to LList                        *}
  161. {*  -> row            pointer to list row, or NULL to delete    *}
  162. {*                    all rows                                *}
  163. {*                                                            *}
  164. {* Deletes the row and releases all of its associated         *}
  165. {* memory.                                                    *}
  166. {*                                                            *}
  167. {************************************************************}
  168.     procedure LLDelRow (theList: LListPtr; row: LRowPtr);
  169.  
  170.  
  171. {************************************************************}
  172. {*                                                            *}
  173. {* LLDispose                                                *}
  174. {*                                                            *}
  175. {*  -> theList        pointer to LList                        *}
  176. {*                                                            *}
  177. {* Disposes of a LList and release all of its memory.        *}
  178. {*                                                            *}
  179. {************************************************************}
  180.     procedure LLDispose (theList: LListPtr);
  181.  
  182.  
  183. {************************************************************}
  184. {*                                                            *}
  185. {* LLDoDraw                                                    *}
  186. {*                                                            *}
  187. {*  -> theList        pointer to LList                        *}
  188. {*  -> dodraw        1=changes to LList are displayed as     *}
  189. {*                    they occur, 0=list will not be             *}
  190. {*                    updated until drawing is turned back on    *}
  191. {*  -> drawNow        1=draw list items that need drawing        *}
  192. {*                    immediately, 0=do not draw now (call    *}
  193. {*                    LLUpdate to force the list to redraw).    *}
  194. {*                    Note: drawNow is ignored if dodraw = 0.    *}
  195. {*                                                            *}
  196. {* Turns list drawing normally performed by other LList     *}
  197. {* Manager functions on or off.                                *}
  198. {*                                                            *}
  199. {************************************************************}
  200.     procedure LLDoDraw (theList: LListPtr; dodraw: integer; drawNow: integer);
  201.  
  202.  
  203. {************************************************************}
  204. {*                                                            *}
  205. {* LLGetCell                                                *}
  206. {*                                                            *}
  207. {*  -> theList        pointer to LList                        *}
  208. {*  -> row            pointer to list row                        *}
  209. {*  -> colNum        column number of cell in row            *}
  210. {*                    (column numbers start at 0)                *}
  211. {* <-> dataLen        on entry size in bytes of buffer at        *}
  212. {*                    data, on return actual length of data    *}
  213. {*                    transferred                                *}
  214. {*  -> data            pointer to buffer, on return this         *}
  215. {*                    buffer contains the data from the cell    *}
  216. {*                                                            *}
  217. {* Get a copy of a cell's data.                                *}
  218. {*                                                            *}
  219. {************************************************************}
  220.     procedure LLGetCell (theList: LListPtr; row: LRowPtr; colNum: integer; var dataLen: integer; data: Ptr);
  221.  
  222.  
  223. {************************************************************}
  224. {*                                                            *}
  225. {* LLGetSelect        returns true if a selected row is         *}
  226. {*                    found, false if not                        *}
  227. {*                                                            *}
  228. {*  -> theList        pointer to LList                        *}
  229. {* <-> row            pointer to list row    pointer                *}
  230. {*                    on entry pointer to a row to test        *}
  231. {*                    first, on return pointer to a selected    *}
  232. {*                    row if a selected row was found            *}
  233. {*  -> advanceit    1=examine one row,0=keep looking        *}
  234. {*                                                            *}
  235. {* Queries if a row is selected; gets the next selected        *}
  236. {* row if advanceit = true. Note that in searching for all    *}
  237. {* selections in a list, you will need to advance row        *}
  238. {* (use LLNextRow) after a selection is found.                *}
  239. {*                                                            *}
  240. {************************************************************}
  241.     function LLGetSelect (theList: LListPtr; var row: LRowPtr; advanceit: integer): integer;
  242.  
  243.  
  244. {************************************************************}
  245. {*                                                            *}
  246. {* LLNew            returns a pointer to a new LList        *}
  247. {*                    (returns NULL if there's not enough     *}
  248. {*                    memory)                                    *}
  249. {*                                                            *}
  250. {*  -> view            pointer to list display    rectangle in    *}
  251. {*                    local coordinates                        *}
  252. {*  -> window        pointer to window where list resides    *}
  253. {*  -> rowHeight    height of a row in pixels                *}
  254. {*                    (if you change LList.height after the    *}
  255. {*                    LLNew call you also need to recalcualte    *}
  256. {*                    LList.numOfVisRows)                        *}
  257. {*  -> numOfColumns    number of columns in the list            *}
  258. {*                    (5 columns would be numbered 0 thru 4)    *}
  259. {*  -> hasScroll    1=list has vertical scroll bar,         *}
  260. {*                    0=no scroll bar                            *}
  261. {*  -> selFlags        determines how selection of rows is     *}
  262. {*                    processed in LLClick calls                *}
  263. {*                    See Values for selFlags above.            *}
  264. {*                                                            *}
  265. {* Allocates and initializes a LList record.                *}
  266. {*                                                            *}
  267. {************************************************************}
  268.     function LLNew (var view: Rect; window: WindowPtr; rowHeight: integer; numOfColumns: integer; hasScroll: integer; selFlags: integer): LListPtr;
  269.  
  270.  
  271. {************************************************************}
  272. {*                                                            *}
  273. {* LLNextRow        returns a pointer to next row            *}
  274. {*                    returns NULL if no next row                *}
  275. {*                                                            *}
  276. {*  -> theList        pointer to LList                        *}
  277. {*  -> row            pointer to a row                        *}
  278. {*                                                            *}
  279. {* Returns a pointer to the row after row. Pass NULL for    *}
  280. {* row and LLNextRow will return a pointer to the first        *}
  281. {* row in the list.                                            *}
  282. {*                                                            *}
  283. {************************************************************}
  284.     function LLNextRow (theList: LListPtr; row: LRowPtr): LRowPtr;
  285.  
  286.  
  287. {************************************************************}
  288. {*                                                            *}
  289. {* LLPrevRow        returns a pointer to previous row        *}
  290. {*                    returns NULL if no previous row            *}
  291. {*                                                            *}
  292. {*  -> theList        pointer to LList                        *}
  293. {*  -> row            pointer to a row                        *}
  294. {*                                                            *}
  295. {* Returns a pointer to the row before row. Pass NULL for    *}
  296. {* row and LLPrevRow will return a pointer to the last        *}
  297. {* row in the list.                                            *}
  298. {*                                                            *}
  299. {************************************************************}
  300.     function LLPrevRow (theList: LListPtr; row: LRowPtr): LRowPtr;
  301.  
  302.  
  303. {************************************************************}
  304. {*                                                            *}
  305. {* LLRect                                                    *}
  306. {*                                                            *}
  307. {*  -> theList        pointer to LList                        *}
  308. {*  -> row            pointer to a row                        *}
  309. {*  -> colFirst        first column to contain rectangle        *}
  310. {*  -> colLast        last column to contain rectangle        *}
  311. {* <-  theRect        local coordindates of rectangle that    *}
  312. {*                    encloses the specified row and columns    *}
  313. {*                                                            *}
  314. {* Obtains the local coordinates of the rectangle that        *}
  315. {* encloses the specified row and column(s).                *}
  316. {*                                                            *}
  317. {************************************************************}
  318.     procedure LLRect (theList: LListPtr; row: LRowPtr; colFirst: integer; colLast: integer; var theRect: Rect);
  319.  
  320.  
  321. {************************************************************}
  322. {*                                                            *}
  323. {* LLScroll                                                    *}
  324. {*                                                            *}
  325. {*  -> theList        pointer to LList                        *}
  326. {*  -> rows            <0 scroll list down specific number of    *}
  327. {*                    rows, >0 scroll list up specific         *}
  328. {*                    number of rows                            *}
  329. {*                                                            *}
  330. {* Scrolls the list a specific number of rows relative        *}
  331. {* to the current displayed rows.                            *}
  332. {*                                                            *}
  333. {************************************************************}
  334.     procedure LLScroll (theList: LListPtr; rows: integer);
  335.  
  336.  
  337. {************************************************************}
  338. {*                                                            *}
  339. {* LLScrollToRow                                            *}
  340. {*                                                            *}
  341. {*  -> theList        pointer to LList                        *}
  342. {*  -> row            pointer to a row                        *}
  343. {*                                                            *}
  344. {* Scrolls the list so that row is the first row displayed.    *}
  345. {* If row is NULL the list scrolls to the bottom.            *}
  346. {*                                                            *}
  347. {************************************************************}
  348.     procedure LLScrollToRow (theList: LListPtr; row: LRowPtr);
  349.  
  350.  
  351. {************************************************************}
  352. {*                                                            *}
  353. {* LLSearch            returns 1 if data is found, 0 if not    *}
  354. {*                                                            *}
  355. {*  -> theList        pointer to LList                        *}
  356. {* <-> row            pointer to pointer to list row            *}
  357. {*                    on entry row to start search at or NULL    *}
  358. {*                    to start search at first row, on return    *}
  359. {*                    row where data was found if found        *}
  360. {* <-  colFound        on return pointer to column number of    *}
  361. {*                    row where data was found, if found        *}
  362. {*  -> colFirst        colFirst and colLast define the range    *}
  363. {*  -> colLast        of columns to search in                    *}
  364. {*  -> data            pointer to buffer containing data to    *}
  365. {*                    search for                                *}
  366. {*  -> dataLen        length of buffer                        *}
  367. {*  -> ignoreCase    1 = comparison is case-insensitive,        *}
  368. {*                    0 = comparison is case-sensitive        *}
  369. {*                                                            *}
  370. {* Searches all columns of all rows beginning at *row         *}
  371. {* for data.                                                 *}
  372. {*                                                            *}
  373. {************************************************************}
  374.     function LLSearch (theList: LListPtr; var row: LRowPtr; var colFound: integer; colFirst: integer; colLast: integer; data: Ptr; dataLen: integer; ignoreCase: integer): integer;
  375.  
  376.  
  377. {************************************************************}
  378. {*                                                            *}
  379. {* LLSetCell                                                *}
  380. {*                                                            *}
  381. {*  -> theList        pointer to LList                        *}
  382. {*  -> row            pointer to list row                        *}
  383. {*  -> colNum        column number of cell in row that will     *}
  384. {*                    receive data (col. nums. start at 0)    *}
  385. {*  -> dataLen        length of buffer                        *}
  386. {*  -> data            pointer to buffer containing data to    *}
  387. {*                    be placed in the cell                    *}
  388. {*                                                            *}
  389. {* Stores a copy of data into a cell.                        *}
  390. {* (If there's not enough memory to copy data into this        *}
  391. {* cell, the cell will be empty.)                            *}
  392. {*                                                            *}
  393. {************************************************************}
  394.     procedure LLSetCell (theList: LListPtr; row: LRowPtr; colNum: integer; dataLen: integer; data: Ptr);
  395.  
  396.  
  397. {************************************************************}
  398. {*                                                            *}
  399. {* LLSetSelect                                                *}
  400. {*                                                            *}
  401. {*  -> theList        pointer to LList                        *}
  402. {*  -> row            pointer to list row    to select or        *}
  403. {*                    deselect                                *}
  404. {*  -> setit        1=select, 0=deselect                    *}
  405. {*                                                            *}
  406. {* Selects or deselects a cell.                                *}
  407. {*                                                            *}
  408. {************************************************************}
  409.     procedure LLSetSelect (theList: LListPtr; row: LRowPtr; setit: integer);
  410.  
  411.  
  412. {************************************************************}
  413. {*                                                            *}
  414. {* LLSort                                                    *}
  415. {*                                                            *}
  416. {*  -> theList        pointer to LList                        *}
  417. {*  -> col1            sort by data field of this column        *}
  418. {*                    number                                    *}
  419. {*  -> col2            sort rows with the same col1 by data    *}
  420. {*                    field of this column number, or -1 for    *}
  421. {*                    no second or third sort field            *}
  422. {*  -> col3            sort rows with the same col2 by data    *}
  423. {*                    field of this column number, or -1 for    *}
  424. {*                    no third sort field                        *}
  425. {*  -> ignoreCase    1 = comparison is case-insensitive,        *}
  426. {*                    0 = comparison is case-sensitive        *}
  427. {*  -> order        1 = sort order is ascending,            *}
  428. {*                    -1 = sort order is descending            *}
  429. {*                                                            *}
  430. {* Sorts and re-draws a list (using a simple bubble-sort).     *}
  431. {*                                                            *}
  432. {************************************************************}
  433.     procedure LLSort (theList: LListPtr; col1: integer; col2: integer; col3: integer; ignoreCase: integer; order: integer);
  434.  
  435.  
  436. {************************************************************}
  437. {*                                                            *}
  438. {* LLUpdate                                                    *}
  439. {*                                                            *}
  440. {*  -> theList        pointer to LList                        *}
  441. {*                                                            *}
  442. {* Redraws the list. Call LLUpdate in response to an update    *}
  443. {* event in the list's window.                                *}
  444. {*                                                            *}
  445. {************************************************************}
  446.     procedure LLUpdate (theList: LListPtr);
  447.  
  448.  
  449. implementation
  450. end. {LList}